﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RestaurentDTA
{
    public partial class ManagerView : Form
    {
        private RestaurantWebService service;
        private IList<string> occupiedTables = new List<string>();
        private IList<TableInfo> tableInfos = new List<TableInfo>();
        private IDictionary<string, TableInfo> tableMap = new Dictionary<string, TableInfo>();
        public ManagerView()
        {
            InitializeComponent();
            InitializeProcessedOrdersData();
        }

        private void InitializeProcessedOrdersData()
        {
            processedOrdersView.View = View.Details;
            processedOrdersView.GridLines = true;
            processedOrdersView.Columns.Add("OrderNo", 100);
            processedOrdersView.Columns.Add("OrderTime", 150);
            processedOrdersView.Columns.Add("Table", 100);
            processedOrdersView.Columns.Add("Seat", 100);
            processedOrdersView.Columns.Add("Meal", 100);
            processedOrdersView.Columns.Add("Status", 100);
        }

        private void fillTableMap()
        {
            tableInfos.Add(new TableInfo("01", table01, RestaurentDTA.Properties.Resources.t_g01, RestaurentDTA.Properties.Resources.t_y01));
            tableInfos.Add(new TableInfo("02", table02, RestaurentDTA.Properties.Resources.t_g02, RestaurentDTA.Properties.Resources.t_y02));
            tableInfos.Add(new TableInfo("03", table03, RestaurentDTA.Properties.Resources.t_g03, RestaurentDTA.Properties.Resources.t_y03));
            tableInfos.Add(new TableInfo("04", table04, RestaurentDTA.Properties.Resources.t_g04, RestaurentDTA.Properties.Resources.t_y04));
            tableInfos.Add(new TableInfo("05", table05, RestaurentDTA.Properties.Resources.t_g05, RestaurentDTA.Properties.Resources.t_y05));
            tableInfos.Add(new TableInfo("06", table06, RestaurentDTA.Properties.Resources.t_g06, RestaurentDTA.Properties.Resources.t_y06));
            tableInfos.Add(new TableInfo("07", table07, RestaurentDTA.Properties.Resources.t_g07, RestaurentDTA.Properties.Resources.t_y07));
            tableInfos.Add(new TableInfo("08", table08, RestaurentDTA.Properties.Resources.t_g08, RestaurentDTA.Properties.Resources.t_y08));
            tableInfos.Add(new TableInfo("09", table09, RestaurentDTA.Properties.Resources.t_g09, RestaurentDTA.Properties.Resources.t_y09));
            tableInfos.Add(new TableInfo("10", table10, RestaurentDTA.Properties.Resources.t_g10, RestaurentDTA.Properties.Resources.t_y10));
            tableInfos.Add(new TableInfo("11", table11, RestaurentDTA.Properties.Resources.t_g11, RestaurentDTA.Properties.Resources.t_y11));
            tableInfos.Add(new TableInfo("12", table12, RestaurentDTA.Properties.Resources.t_g12, RestaurentDTA.Properties.Resources.t_y12));
            tableInfos.Add(new TableInfo("13", table13, RestaurentDTA.Properties.Resources.t_g13, RestaurentDTA.Properties.Resources.t_y13));
            tableInfos.Add(new TableInfo("14", table14, RestaurentDTA.Properties.Resources.t_g14, RestaurentDTA.Properties.Resources.t_y14));
            tableInfos.Add(new TableInfo("15", table15, RestaurentDTA.Properties.Resources.t_g15, RestaurentDTA.Properties.Resources.t_y15));

            foreach (TableInfo t in tableInfos)
            {
                tableMap.Add(t.TableNo.ToString(), t);
            }
        }


        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void onVacancy(object sender, EventArgs e)
        {

        }

        private void onOccupy(object sender, EventArgs e)
        {

        }

        private void LoadOrders(object sender, EventArgs e)
        {
           
        }

        private void OnManagerViewLoad(object sender, EventArgs e)
        {

        }

        private void OnKitchenRecentlySent(object sender, EventArgs e)
        {

        }

        private void SummaryView(object sender, EventArgs e)
        {
            
        }

        private void OnRoomView(object sender, EventArgs e)
        {
            service = new RestaurantWebService();
            for(int i=1; i<=15; i++)
            {
                if (service.getTableOccupancy(i))
                {
                    TableInfo tableInfo = tableMap[i.ToString()];

                    pictureBox.Image = tableInfo.OccupiedImage;
                    occupiedTables.Add(tableInfo.TableNo);
                }

            }
            
        }

        private void OnPendingOrdersView(object sender, EventArgs e)
        {
            service = new RestaurantWebService();
            Order[] orderArr = service.getPendingOrders();
            int saladcount=0, burgercount=0, fishcount=0, pastacount=0, pizzacount=0;

            foreach (Order o in orderArr)
            {
                Meal meal = o.Meal;

              if (o.Status.ToString() == "Placed")
                {
                    if (meal.Name == "Salad")
                        saladcount++;
                    else if (meal.Name == "Burger")
                        burgercount++;
                    else if (meal.Name == "Fish and Chips")
                        fishcount++;
                    else if (meal.Name == "Pasta")
                        pastacount++;
                    else if (meal.Name == "Pizza")
                        pizzacount++;
                }
            }

            saladOrders.Text = saladcount.ToString();
            burgerOrders.Text = burgercount.ToString();
            FishnChipsOrders.Text = fishcount.ToString();
            pastaOrders.Text = pastacount.ToString();
            pizzaOrders.Text = pizzacount.ToString();

        }

        private void OnProcessedOrderView(object sender, EventArgs e)
        {
            service = new RestaurantWebService();

            Order[] processedOrderArr = service.getOrdersToBeDelivered();
            ListViewItem item;
            foreach (Order order in processedOrderArr)
            {
                item = new ListViewItem(new string[] { 
                    order.OrderNumber.ToString(),
                    order.OrderTime.ToString(),
                    order.TableNumber.ToString(), 
                    order.SeatNumber.ToString(),
                    order.Meal.Name,
                    order.Status.ToString(),
                    
                });

                processedOrdersView.Items.Add(item);
            }
            /*foreach(Order o in processedOrderArr)
            {
                Meal meal = o.Meal;

                processedOrdersTxt.Text += "TableNo: " + o.TableNumber + " Seat No: " + o.SeatNumber + " Meal: "+ meal.Name +"\r\n";
            }*/
        }


        private void OnSummaryView(object sender, EventArgs e)
        {
            MessageBox.Show("aa");
            service = new RestaurantWebService();
            popularMealTxt.Text = service.getMostPopularMeal().Name;
            popularTableTxt.Text = service.getMostPopularTable().TableNumber.ToString();
           // totalMealsTxt.Text = service.
        }

        private void panel5_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {

        }

        private void DeliverSaladOrder(object sender, EventArgs e)
        {
            service = new RestaurantWebService();
            Order[] orderArr = service.getPendingOrders();
            foreach (Order o in orderArr)
            {
                Meal meal = o.Meal;

                if (o.Status.ToString() == "Placed" && meal.Name == "Salad")
                {
                    service.indicateReady(o);
                }
            }

            saladOrders.Text = "0";
        }

        private void DeliverBurgerOrder(object sender, EventArgs e)
        {
            service = new RestaurantWebService();
            Order[] orderArr = service.getPendingOrders();
            foreach (Order o in orderArr)
            {
                Meal meal = o.Meal;

                if (o.Status.ToString() == "Placed" && meal.Name == "Burger")
                {
                    service.indicateReady(o);
                }
            }

            burgerOrders.Text = "0";
        }

        private void DeliverFishOrder(object sender, EventArgs e)
        {
            service = new RestaurantWebService();
            Order[] orderArr = service.getPendingOrders();
            foreach (Order o in orderArr)
            {
                Meal meal = o.Meal;

                if (o.Status.ToString() == "Placed" && meal.Name == "Fish and Chips")
                {
                    service.indicateReady(o);
                }
            }

            FishnChipsOrders.Text = "0";
        }

        private void DeliverPastaOrder(object sender, EventArgs e)
        {
            service = new RestaurantWebService();
            Order[] orderArr = service.getPendingOrders();
            foreach (Order o in orderArr)
            {
                Meal meal = o.Meal;

                if (o.Status.ToString() == "Placed" && meal.Name == "Pasta")
                {
                    service.indicateReady(o);
                }
            }

            pastaOrders.Text = "0";
        }

        private void DeliverPizzaOrder(object sender, EventArgs e)
        {
            service = new RestaurantWebService();
            Order[] orderArr = service.getPendingOrders();
            foreach (Order o in orderArr)
            {
                Meal meal = o.Meal;

                if (o.Status.ToString() == "Placed" && meal.Name == "Pizza")
                {
                    service.indicateReady(o);
                }
            }

            pizzaOrders.Text = "0";
        }
    }

    public class TableInfo
    {
        private string tableNo;
        private PictureBox pictureBox;
        private Bitmap occupiedImage;
        private Bitmap vacantImage;

        public TableInfo(string tableNo, PictureBox pictureBox, Bitmap occupiedImage, Bitmap vacantImage)
        {
            this.tableNo = tableNo;
            this.pictureBox = pictureBox;
            this.occupiedImage = occupiedImage;
            this.vacantImage = vacantImage;
        }

        public string TableNo
        {
            get { return tableNo; }
            set { tableNo = value; }
        }
        public PictureBox PictureBox
        {
            get { return pictureBox; }
            set { pictureBox = value; }
        }
        public Bitmap OccupiedImage
        {
            get { return occupiedImage; }
            set { occupiedImage = value; }
        }
        public Bitmap VacantImage
        {
            get { return vacantImage; }
            set { vacantImage = value; }
        }
    }
}
